import React, { createContext, useContext } from "react";

export const createContextApi = <T={}>(initialValue: Partial<T>) => {
    const Context = createContext(initialValue);
    return {
        Provider: ({ children, ...others }: any) => {
            const nextContext = {
                ...initialValue,
                ...others
            };
            return <Context.Provider value={nextContext}>{children}</Context.Provider>
        },
        useApi: () => useContext<T>(Context as any),
    }
};
